#!/bin/bash
KYLX_BIN="${BASH_SOURCE-$0}"
KYLX_BIN="$(dirname "${KYLX_BIN}")"
KYLX_BIN_DIR="$(cd "${KYLX_BIN}"; pwd)"
KYLX_HOME="${KYLX_BIN_DIR}"
KYLX_CFG_DIR="$KYLX_HOME""/config"
LOG4JPATH="$KYLX_CFG_DIR/log4j2.xml"
echo $LOG4JPATH
CLASSPATH="$KYLX_CFG_DIR"
echo "classpath:" $CLASSPATH
pwd
APP_NAME="templateProject-1.0.1-RELEASE-exec.jar"
start(){
	echo "Starting $APP_NAME..."
	nohup java -Dlog4j.configurationFile=$LOG4JPATH     -Xbootclasspath/a:$CLASSPATH  -jar $APP_NAME &
	echo "$APP_NAME started."
}
stop(){
	echo "Stopping $APP_NAME..."
		PID=$(ps aux | grep $APP_NAME | grep -v grep | awk '{print $2}')
	if [ -z "$PID" ]; then
		echo "$APP_NAME is not running."
	else
		kill -9 $PID
		echo "$APP_NAME stopped."
	fi
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 2
        start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac
